﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Snowdreamist.Text.UBB
{
    internal class FontFactory : PrefixUBBElementFactory
    {
        public FontFactory() : base(ElementPrefix) { }

        public override UBBElement Create(UBBContent ubbContent)
        {
            var matchResult = ElementRegex.Match(ubbContent.Text);
            if (!matchResult.Success)
                return null;
            return new FontElement(matchResult.Groups[1].Value);
        }

        #region private

        private readonly static string ElementPrefix = "font";

        private readonly static Regex ElementRegex = new Regex("font=(.*)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);

        #endregion private
    }

    public class FontElement : UBBElement
    {
        public const string Label = "font";

        public FontElement(string fontFamily)
            : base(Label)
        {
            this.FontFamily = fontFamily;
        }

        /// <summary>
        /// Font family
        /// </summary>
        public string FontFamily { get; private set; }

        public override string SerializeToUBBCode()
        {
            return Label + "=" + this.FontFamily;
        }

        public override object Clone()
        {
            return new FontElement(this.FontFamily);
        }
    }
}